#if !defined(__APP_BUFFER_H)
#define __APP_BUFFER_H
#include <pthread.h>

//小缓冲区
typedef struct 
{
   unsigned char *ptr;
    int size;
    int len;
} SubBuffer;

//大缓冲区
typedef struct 
{
    SubBuffer *sub_buffers[2]; //小缓冲区数组
    int  read_index;  //读小缓冲区索引
    int  write_index; //写小缓冲区索引
    pthread_mutex_t read_lock; //读取互斥锁
    pthread_mutex_t write_lock; //写入互斥锁
}Buffer;

//初始化缓冲区
Buffer *app_buffer_init(int size);

//释放缓冲区
void app_buffer_free(Buffer *buffer);

//写入数据到缓冲区
int app_buffer_write(Buffer *buffer, char *data, int len);
//从缓冲区读取数据
int app_buffer_read(Buffer *buffer, char *data_buf, int buf_size);



#endif // MACRO


